﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HR.Appointments.Service;

public partial class DisplayAllCompanies : AdminPage
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        
        CheckAdmin();
        _imgConfirm.Visible = IsLoggedIn;
        if (!IsPostBack)
        {
            ListAllCompanies();
        }
    }
    
    protected void _dtgAllcompanies_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
		System.Collections.Specialized.OrderedDictionary keys =
			(System.Collections.Specialized.OrderedDictionary)_dtgAllcompanies.DataKeys[e.RowIndex].Values;

        try
        {
            int companyId = Convert.ToInt32(keys["CompanyId"]);
            Facade.Employee().DeleteCompany(companyId);
        }
        catch (SubmitException)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "ErrorAlert", "alert('Ekki tókst að eyða.');", true);
            return;
        }
		ListAllCompanies();

    }
    #endregion

    #region Link Transfers
    protected void _ibmHomePage_Click(object sender, ImageClickEventArgs e)
	{
        if (!IsPostBack || (e.X != 0 && e.Y != 0))
        {
            Server.Transfer("~/Company.aspx",true);
        }
    }
    #endregion

    #region Private List Methods
    private void ListAllCompanies()
    {
        _dtgAllcompanies.DataSource = Facade.Administrator().GetAllCompanyCompanies();
        _dtgAllcompanies.DataBind();
    }
    #endregion
}
